package com.hsjk.szwj.module.official.controller.admin.unit;

import com.hsjk.szwj.framework.common.pojo.CommonResult;
import com.hsjk.szwj.framework.common.pojo.PageResult;
import com.hsjk.szwj.module.official.controller.admin.unit.vo.AdminModuleBannerDetailRespVO;
import com.hsjk.szwj.module.official.controller.admin.unit.vo.AdminModuleFeedCreateReqVO;
import com.hsjk.szwj.module.official.controller.admin.unit.vo.AdminModuleFeedDetailRespVO;
import com.hsjk.szwj.module.official.controller.admin.unit.vo.AdminModuleFeedPageReqVO;
import com.hsjk.szwj.module.official.controller.admin.unit.vo.AdminModuleFeedPageRespVO;
import com.hsjk.szwj.module.official.controller.admin.unit.vo.AdminModuleFeedUpdateReqVO;
import com.hsjk.szwj.module.official.service.unit.IUnitService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.annotation.security.PermitAll;
import javax.validation.Valid;

import static com.hsjk.szwj.framework.common.pojo.CommonResult.success;

/**
 * @author chenjiawei
 * @desc
 * @Date 2023/11/26 15:24
 **/
@Tag(name = "后台管理端 - 官网模块化信息流相关接口")
@RestController
@RequestMapping("/official-website/unit/feed")
@Validated
public class AdminUnitFeedController {
    @Resource
    private IUnitService unitService;

    @PostMapping("/create")
    @Operation(summary = "创建信息流")
//    @PreAuthorize("@ss.hasPermission('official-website:unit:feed:create')")
    @PermitAll
    public CommonResult<Boolean> createModuleFeed(@RequestBody @Valid AdminModuleFeedCreateReqVO reqVO) {
        return success(unitService.createModuleFeed(reqVO));
    }

    @GetMapping("/get-feed-by-id")
    @Operation(summary = "根据信息流id获取信息流详情")
    @PreAuthorize("@ss.hasPermission('official-website:unit:feed:query')")
    public CommonResult<AdminModuleFeedDetailRespVO> getAdminModuleFeedDetail(@RequestParam Long id) {
        return success(unitService.getAdminModuleFeedDetail(id));
    }

    @PostMapping("/update")
    @Operation(summary = "修改信息流")
    @PreAuthorize("@ss.hasPermission('official-website:unit:feed:update')")
    public CommonResult<Boolean> updateModuleFeed(@RequestBody @Valid AdminModuleFeedUpdateReqVO reqVO) {
        return success(unitService.updateModuleFeed(reqVO));
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除信息流")
    @PreAuthorize("@ss.hasPermission('official-website:unit:feed:delete')")
    public CommonResult<Boolean> deleteModuleFeed(@RequestParam("id") Long id) {
        return success(unitService.deleteModuleFeed(id));
    }

    @PostMapping("/page")
    @Operation(summary = "分页查询信息流")
//    @PreAuthorize("@ss.hasPermission('official-website:unit:feed:query')")
    @PermitAll
    public CommonResult<PageResult<AdminModuleFeedPageRespVO>> getAdminModuleFeedPage(@RequestBody @Valid AdminModuleFeedPageReqVO reqVO) {
        return success(unitService.getAdminModuleFeedPage(reqVO));
    }
}
